<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      // 需求 用户输入5个数 有效年龄（0-100）放入按钮
      let arr = [];
      //  用户一旦输入了有效数字 就push到arr里面取 有效意味要判断
      // for （）{}做五次确实用户收到五个弹窗但是不能做到5个有效
      while (arr.length < 5) {
        let num = +prompt(`请输入第${arr.length + 1}有效年龄`);
        if (num < 100 && num > 0) {
          arr.push(num);
        }
      }
      console.log(arr);
      //  需求筛选出大于等于18的年龄
      // 遍历arr数组
      let adult = [];
      let sum = 0;
      let average = 0;
      let max = arr[0];
      let least = arr[0];
      for (let i = 0; i < arr.length; i++) {
        if (arr[i] >= 18) {
          adult.push(arr[i]);
        }
        // 最大值
        if (arr[i] > max) {
          max = arr[i];
        }
        // 最小值 v
        if (arr[i] < least) {
          least = arr[i];
        }
        sum += arr[i];
        average = sum / arr.length;
      }

      console.log(adult);
      console.log(sum);
      console.log(average);
      console.log(max);
      console.log(least);
    </script>
  </body>
</html>
